package com.hk.huakangcompany.handler.exception;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @Author: aerfazhe
 * @Date: 2021/7/14 9:28
 * @Statement: 该类拦截所有Controller
 */
@ControllerAdvice
public class CommonExceptionHandler {

    /**
     * 对异常进行分类处理
     * @param e
     * @return
     */
    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> handlerException(LyException e) {
        return ResponseEntity.status(e.getExceptionEnum().getCode()).body(new ExceptionResult(e.getExceptionEnum()));
    }


}
